/*
 * VANET simulator
 * 01-12-2010, Johan Lukkien and Tse
 *
 * This program simulates a collection of nodes with a periodic broadcasting behavior.
 */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "random.h"
#include "channel.h"
#include <string.h>


#define TRUE  		 1
#define FALSE 		 0

#define UNDEFINED  	-1
#define historyLength  	 3	/* for estimating the channel load */
#define eIMaxNumber  	 3	/* for estimating the channel load */

/*
* Constants
*/
#define SPEED_OF_LIGHT 299792458

/*
 * MAC State machine execution states
 */

#define E_IDLE       	0
#define E_WAITAIFS   	1
#define E_DEFERRING  	2
#define E_COUNTING   	3
#define E_XMIT       	4
#define E_END        	5

/*
 * Phy Execution states
 */

#define PHY_SEARCHING      	-1
#define PHY_RECEIVING   	 1

const char *State2String[] = {
  "IDLE",
  "WAITAIFS",
  "E_DEFERING",
  "COUNTING",
  "XMIT"
};

typedef struct ModulationParam {
	int schemeIndex;
	char schemeName[10];
	double SINR_dB;
	double SINR_ratio;
	int NDBPS; //Data Bits Per Symbol
} ModulationParam;

const struct ModulationParam modulation_table[4] = {
//  mod  name  SINRdB   SINR  NDBPS bit
               	{ 0, "BPSK", 5, 3.1623, 24 }, { 1, "QPSK", 8, 6.3096, 48 }, { 2,
                               	"QAM16", 15, 31.6228, 96 }, { 3, "QAM64", 25, 316.2278, 192 } };

typedef struct {
  double enteringTS,	
	 leavingTS,
  	 LT, 			/* Link Life Time (LT) i.e. enteringTS - leavingTS */			
	 FD,				/* First Delay */
	 NoM, 			/* The longest No Message Interval (NoM) in a link */			
	 msgRcvdTSs[historyLength],
  	 theLastMsgRcvdTS;
} encounterInterval;

typedef struct {
  encounterInterval eI[eIMaxNumber];
} Link;

typedef struct {
  int 	Range,
  	    *Reach, 
  	    *Recvd;
  char 	*str;
} Message;

typedef struct {
  int 	aNumV,
  	    *IDs; 
} activeVehicles;

typedef struct {
  int 	 ExState,
         PhyState,
      	 Iter,
         elPhase,
      	 Content,
      	 Count,
      	 doCount,
      	 AIFS,
      	 yloc,
      	 DataSize,
      	 Xmit, 
      	 Recs, 
      	 Miss,
      	 *eCount,
      	 slotCount;
 double  Next,
         NextMsgTime,
         xloc, 
         Range,
         Period,
	     initialPhase,        
	     Phase,         
	     SMR,
         aMsgDelay,
         Pt,
         *Pr,
         maxPr,
         cumlPr;
 Message Msg;
 Link 	*Link;
} Vehicle;


